package com.ruoyi.web.controller.ziran;

import java.util.List;

import com.ruoyi.ziran.domain.ZrQuestionBank;
import com.ruoyi.ziran.domain.ZrQuestionBankItem;
import com.ruoyi.ziran.service.IZrQuestionBankService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ziran.domain.ZrPaper;
import com.ruoyi.ziran.service.IZrPaperService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Controller
@RequestMapping("/ziran/zrPaper")
public class ZrPaperController extends BaseController
{
    private String prefix = "ziran/zrPaper";

    @Autowired
    private IZrPaperService zrPaperService;
    @Autowired
    private IZrQuestionBankService iZrQuestionBankService;

    //@RequiresPermissions("ziran:zrPaper:view")
    @GetMapping()
    public String zrPaper()
    {
        return prefix + "/zrPaper";
    }

    /**
     * 查询试卷列表
     */
    //@RequiresPermissions("ziran:zrPaper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZrPaper zrPaper)
    {
        startPage();
        List<ZrPaper> list = zrPaperService.selectZrPaperList(zrPaper);
        return getDataTable(list);
    }

    /**
     * 导出试卷列表
     */
    //@RequiresPermissions("ziran:zrPaper:export")
    @Log(title = "试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZrPaper zrPaper)
    {
        List<ZrPaper> list = zrPaperService.selectZrPaperList(zrPaper);
        ExcelUtil<ZrPaper> util = new ExcelUtil<ZrPaper>(ZrPaper.class);
        return util.exportExcel(list, "试卷数据");
    }

    /**
     * 新增试卷
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        //查询所有题
        ZrQuestionBank zrQuestionBank=new ZrQuestionBank();
        List<ZrQuestionBank> list=iZrQuestionBankService.selectZrQuestionBankList(zrQuestionBank);
        mmap.put("list", list);
        return prefix + "/add";
    }

    /**
     * 新增保存试卷
     */
    //@RequiresPermissions("ziran:zrPaper:add")
    @Log(title = "试卷", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZrPaper zrPaper)
    {
        return toAjax(zrPaperService.insertZrPaper(zrPaper));
    }

    /**
     * 修改试卷
     */
    //@RequiresPermissions("ziran:zrPaper:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrPaper zrPaper = zrPaperService.selectZrPaperById(id);
        mmap.put("zrPaper", zrPaper);
        return prefix + "/edit";
    }

    /**
     * 查看试卷详情
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/info/{id}")
    public String info(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrPaper zrPaper = zrPaperService.selectZrPaperById(id);
        mmap.put("zrPaper", zrPaper);
        return prefix + "/info";
    }
    @GetMapping("/answer/{id}")
    public String answer(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrPaper zrPaper = zrPaperService.selectZrPaperById(id);
        mmap.put("zrPaper", zrPaper);
        return prefix + "/answer";
    }

    /**
     * 修改保存试卷
     */
    //@RequiresPermissions("ziran:zrPaper:edit")
    @Log(title = "试卷", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZrPaper zrPaper)
    {
        return toAjax(zrPaperService.updateZrPaper(zrPaper));
    }

    /**
     * 删除试卷
     */
    //@RequiresPermissions("ziran:zrPaper:remove")
    @Log(title = "试卷", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zrPaperService.deleteZrPaperByIds(ids));
    }
}
